using System.Threading;
using System.Windows;
using ApprovalTests;
using ApprovalTests.Reporters;
using Microsoft.SmallBasic.Library;

namespace SmallBasicFun.Tests
{
	public class ApprovalHelper
	{
		static ApprovalHelper()
		{
			ProgramWindow.AbortTracking();
		}
		public static void ApproveProgramWindow()
		{
			var window = ProgramWindow.GetWindow();
			Approve(window);
		}

		
		private static void Approve(Window window)
		{
			Program.Delay(150);
			try
			{
				Approvals.Verify(new DispatchedWindowWpfWriter(window));
			}
			finally
			{
				ResetGraphics();
			}
		}


		public static void ResetGraphics()
		{
			ResetGraphicsWindow();
			GraphicsWindowHelper.ResetTurtle();
			ColorWheel.RemoveAllColors();
			ShapeMaker.RestoreDefaults();
			MyTurtle.forceAnimateTime = 0;
		}

		private static void ResetGraphicsWindow()
		{
			GraphicsWindow.PenColor = Colors.Black;
			GraphicsWindow.BackgroundColor = Colors.White;
			GraphicsWindow.FontItalic = "False";
			GraphicsWindow.FontBold = "True";
			Thread.Sleep(50);
			GraphicsWindow.PenWidth = 2;
			GraphicsWindow.BrushColor = Colors.CornflowerBlue;
			GraphicsWindow.FontName = Fonts.Tahoma;
			GraphicsWindow.FontSize = 12;
			GraphicsWindow.Clear();
		}
	}
}